package com.yswy.common.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class HyCustomDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {

	private static Logger log = LoggerFactory.getLogger(HyCustomDateTimeDeserializer.class);
	
    @Override  
    public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt)
            throws IOException, JsonProcessingException {
    	
    	if(jp.getText() == null || jp.getText().equals("")){
    		return null;
    	}
        return LocalDateTime.parse(jp.getText(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
    }  
} 